import os
import config
from TaskManager import TaskManager

if not os.path.exists(config.save_path):
    os.mkdir(config.save_path)

task_manager = TaskManager()

files = [os.path.join('test_img', x) for x in os.listdir('test_img')]
# print(files)

tasks = []


def gen_all_conditions(path, depth, switch):
    global tasks
    if depth == 4:
        tasks.append((tuple(switch), path))
        return

    switch[depth] = False
    gen_all_conditions(path, depth + 1, switch)
    switch[depth] = True
    gen_all_conditions(path, depth + 1, switch)
    return


def gen_tasks(file_path_list: list):
    for f in file_path_list:
        sw = [False, False, False, False]
        gen_all_conditions(f, 0, switch=sw)

    # print(tasks)
    task_manager.add_tasks(tasks)


def auto_detect(file_path_list: list):
    for f in file_path_list:
        task_manager.add_task(f)


# 自动枚举所有的可能的切分方式，把他们加到任务队列
# gen_tasks(files)

# 由任务管理器决定切分方式
auto_detect(files)

# 运行任务
task_manager.run()
